import { useState } from "react";
import { Switch } from "tdesign-react";
import "./index.scss";


/**
 * 开关单元行
 * @param props 
 * @returns 
 */
const SwitchCell = (props: {
  label: string;
  onChange?: (value: boolean) => void;
}) => {
  const { label, onChange } = props;
  const [checked, setChecked] = useState<boolean>(false);

  const onSwitchChange = (value: boolean) => {
    setChecked(value);
    if (onChange) {
      onChange(value)
    }
  }
  return (
    <div className="switch-cell">
      <span className="switch-cell__label">{label}</span>
      <Switch value={checked} onChange={onSwitchChange} />
    </div>
  )
};


export default SwitchCell;